//
//  MovementImageView.m
//  Portable Traffic Signal Assistor
//
//  Created by Hao Xu on 6/4/12.
//  Copyright (c) 2012 TTU. All rights reserved.
//

#import "MovementImageView.h"

@implementation MovementImageView
static const int NORTHBOUND_POSITION_X=95;
static const int NORTHBOUND_POSITION_Y=155;
static const int SOUTHBOUND_POSITION_X=35;
static const int SOUTHBOUND_POSITION_Y=5;
static const int EASTBOUND_POSITION_X=5;
static const int EASTBOUND_POSITION_Y=105;
static const int WESTBOUND_POSITION_X=155;
static const int WESTBOUND_POSITION_Y=30;
static const int NORTHSOUTH_WIDTH=25;
static const int NORTHSOUTH_HEIGHT=42;
static const int WESTEAST_WIDTH=42;
static const int WESTEAST_HEIGHT=25;

@synthesize phaseID=_phaseID;
@synthesize ringID=_ringID;
@synthesize direction=_direction;
@synthesize movement=_movement;
@synthesize imageName=_imageName;

-(void) dealloc
{
    [_phaseID release];
    [_ringID release];
    [_direction release];
    [_movement release];
    [_imageName release];
    [super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

-(void) setFrameByDirection
{
    if (!self.direction||!self.movement) {
        return;
    }
    NSString *directionMovement=[NSString stringWithFormat:@"%@%@",self.direction,self.movement];
    if ([directionMovement isEqualToString:@"NL"]) {
        CGRect imageViewRect = CGRectMake(NORTHBOUND_POSITION_X,  NORTHBOUND_POSITION_Y, NORTHSOUTH_WIDTH , NORTHSOUTH_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"NT"]) {
        CGRect imageViewRect = CGRectMake(NORTHBOUND_POSITION_X+NORTHSOUTH_WIDTH,  NORTHBOUND_POSITION_Y, NORTHSOUTH_WIDTH , NORTHSOUTH_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"NR"]) {
        CGRect imageViewRect = CGRectMake(NORTHBOUND_POSITION_X+NORTHSOUTH_WIDTH*2,  NORTHBOUND_POSITION_Y, NORTHSOUTH_WIDTH , NORTHSOUTH_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }
    else if ([directionMovement isEqualToString:@"SL"]) {
        CGRect imageViewRect = CGRectMake(SOUTHBOUND_POSITION_X+NORTHSOUTH_WIDTH*2,  SOUTHBOUND_POSITION_Y, NORTHSOUTH_WIDTH , NORTHSOUTH_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"ST"]) {
        CGRect imageViewRect = CGRectMake(SOUTHBOUND_POSITION_X+NORTHSOUTH_WIDTH,  SOUTHBOUND_POSITION_Y, NORTHSOUTH_WIDTH , NORTHSOUTH_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"SR"]) {
        CGRect imageViewRect = CGRectMake(SOUTHBOUND_POSITION_X,  SOUTHBOUND_POSITION_Y, NORTHSOUTH_WIDTH , NORTHSOUTH_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }
    else if ([directionMovement isEqualToString:@"EL"]) {
        CGRect imageViewRect = CGRectMake(EASTBOUND_POSITION_X ,  EASTBOUND_POSITION_Y, WESTEAST_WIDTH , WESTEAST_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"ET"]) {
        CGRect imageViewRect = CGRectMake(EASTBOUND_POSITION_X,  EASTBOUND_POSITION_Y+WESTEAST_HEIGHT, WESTEAST_WIDTH , WESTEAST_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"ER"]) {
        CGRect imageViewRect = CGRectMake(EASTBOUND_POSITION_X,  EASTBOUND_POSITION_Y+WESTEAST_HEIGHT*2, WESTEAST_WIDTH , WESTEAST_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }
    else if ([directionMovement isEqualToString:@"WR"]) {
        CGRect imageViewRect = CGRectMake(WESTBOUND_POSITION_X ,  WESTBOUND_POSITION_Y, WESTEAST_WIDTH , WESTEAST_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"WT"]) {
        CGRect imageViewRect = CGRectMake(WESTBOUND_POSITION_X,  WESTBOUND_POSITION_Y+WESTEAST_HEIGHT, WESTEAST_WIDTH , WESTEAST_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }else if ([directionMovement isEqualToString:@"WL"]) {
        CGRect imageViewRect = CGRectMake(WESTBOUND_POSITION_X,  WESTBOUND_POSITION_Y+WESTEAST_HEIGHT*2, WESTEAST_WIDTH , WESTEAST_HEIGHT);
        self.frame = imageViewRect;
        self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    }
}

@end
